package cn.qg.biz.service.qgorder;
import cn.qg.beans.pojo.QgOrder;
import cn.qg.common.Constants;
import cn.qg.common.EmptyUtils;
import cn.qg.common.Page;
import cn.qg.mapper.qgorder.QgOrderMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class QgOrderServiceImpl implements QgOrderService {

    @Resource
    private QgOrderMapper qgOrderMapper;

    @Override
    public QgOrder getQgOrderById(Long id)throws Exception{
        return qgOrderMapper.getQgOrderById(id);
    }

    @Override
    public List<QgOrder> getQgOrderListByMap(Map<String,Object> param)throws Exception{
        return qgOrderMapper.getQgOrderListByMap(param);
    }

    @Override
    public Integer getQgOrderCountByMap(Map<String,Object> param)throws Exception{
        return qgOrderMapper.getQgOrderCountByMap(param);
    }

    @Override
    public Integer qgtxAddQgOrder(QgOrder qgOrder)throws Exception{
            qgOrder.setCreatedTime(new Date());
            return qgOrderMapper.insertQgOrder(qgOrder);
    }

    @Override
    public Integer qgtxModifyQgOrder(QgOrder qgOrder)throws Exception{
        qgOrder.setCreatedTime(new Date());
        return qgOrderMapper.updateQgOrder(qgOrder);
    }

    @Override
    public Integer qgtxDeleteQgOrderById(Long id)throws Exception{
        return qgOrderMapper.deleteQgOrderById(id);
    }

    @Override
    public Page<QgOrder> queryQgOrderPageByMap(Map<String,Object> param,Integer pageNo,Integer pageSize)throws Exception{
        Integer total = qgOrderMapper.getQgOrderCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<QgOrder> qgOrderList = qgOrderMapper.getQgOrderListByMap(param);
        page.setRows(qgOrderList);
        return page;
    }

}
